package com.junzhiit.nengji.dao.impl;

import java.util.List;

import org.springframework.stereotype.Repository;

import com.bainaeco.framework.base.dao.AbstractBaseDAO;
import com.bainaeco.framework.common.jdbc.StatementParameter;
import com.bainaeco.framework.enums.IsDelete;
import com.junzhiit.nengji.dao.RevenueSettingDAO;
import com.junzhiit.nengji.model.RevenueSetting;

@Repository
public class RevenueSettingDAOImpl extends AbstractBaseDAO<RevenueSetting> implements RevenueSettingDAO {

	@Override
	public List<RevenueSetting> findAll(int pageNumber, int maxPageRow, Integer type) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from revenue_setting where is_delete = ?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(type != null){
			sql.append(" and type = ?");
			params.setInt(type);
		}
		return queryForPagingList(sql.toString(), RevenueSetting.class, params,pageNumber,maxPageRow);
	}

	
	@Override
	public int getTotalCount(Integer type) {
		StringBuffer sql = new StringBuffer();
		sql.append("select count(*) from revenue_setting where is_delete = ?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(type != null){
			sql.append(" and type = ?");
			params.setInt(type);
		}
		return queryForInt(sql.toString(),params);
	}


	@Override
	public int checkType(Integer type) {
		String sql = "select count(*) from revenue_setting where is_delete =? and type = ?";
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		params.setInt(type);
		return queryForInt(sql,params);
	}


	@Override
	public RevenueSetting getRevenue(Integer type) {
		StringBuffer sql = new StringBuffer();
		sql.append("select * from revenue_setting where is_delete = ?");
		StatementParameter params = new StatementParameter();
		params.setInt(IsDelete.NO.toIntValue());
		if(type != null){
			sql.append(" and type = ?");
			params.setInt(type);
		}
		return super.query(sql.toString(), RevenueSetting.class, params);
	}
	
	
}
